package itbour.onetouchshow.utils.glide;


import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.module.GlideModule;


public class CustomGlideModule implements GlideModule {

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); // 设置图片质量为高质量
        builder.setMemoryCache(new LruResourceCache(10 * 1024 * 1024));

//        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
//
//        // MemorySizeCalculator.Builder builder1=new MemorySizeCalculator.Builder(context);
//        MemorySizeCalculator calculator = MemorySizeCalculator.class.cast(context);
//        //  MemorySizeCalculator calculator = new MemorySizeCalculator(builder1);
//        int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
//        int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
//        int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
//        int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
//        builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); //设置图片缓存策略
//        builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
//        int cacheSize100MegaBytes = 104857600;  //100M
//        String downloadDirectoryPath = Environment.getExternalStorageDirectory().getPath();
//        builder.setDiskCache(new DiskLruCacheFactory(downloadDirectoryPath, "cache/", cacheSize100MegaBytes));
        // builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)

    }


    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        // glide.register(GlideUrl.class, InputStream.class, new HttpUrlGlideUrlLoader.Factory());
    }

}